import {createApp} from "vue";
import {createRouter, createWebHistory, Router} from "vue-router"
import App from "./App.vue";
import {renderWithQiankun, qiankunWindow} from 'vite-plugin-qiankun/dist/helper';
import {routes} from "./route/route";

/**
 * 应用每次进入都会调用 mount 方法，通常我们在这里触发应用的渲染方法
 */
function render() {
    const history = createWebHistory(qiankunWindow.__POWERED_BY_QIANKUN__ ? '/vite' : '/');
    const router = createRouter({
        history,
        routes,
    });

    console.log("render")

    createApp(App).use(router).mount("#viteTest");
}

renderWithQiankun({
    bootstrap: async () => {
        console.log("react app bootstraped");
    },
    mount: async (props: any) => {
        console.log(props);
        render();
    },

    /**
     * 应用每次 切出/卸载 会调用的方法，通常在这里我们会卸载微应用的应用实例
     */
    unmount: async (props: any) => {
        console.log(props);
    },

    /**
     * 可选生命周期钩子，仅使用 loadMicroApp 方式加载微应用时生效
     */
    update: async (props: any) => {
        console.log("update props", props);
    },
})

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
    render();
}
